class Solution {
public:
    int maxSubarraySumCircular(vector<int>& nums) {
        int n=nums.size();
        int max_r_turn=nums[0];
        int r_turn=nums[0];
        for(int i=1;i<n;i++){
            int temp=nums[i];
            r_turn=max(temp,temp+r_turn);
            max_r_turn=max(max_r_turn,r_turn);
        }
        int min_l_turn=nums[0];
        int max_l_turn=nums[0];
        int l_turn=nums[0];
        for(int i=1;i<n;i++){
            int temp=nums[i];
            l_turn=min(temp,temp+l_turn);
            min_l_turn=min(min_l_turn,l_turn);
        }
        int sum=0;
        for(int i=0;i<n;i++){
            sum+=nums[i];
        }
        max_l_turn=sum-min_l_turn;
         if(max_l_turn==0){
            return max_r_turn;
        }
        return max(max_r_turn, max_l_turn);
    }
};
